package com.parkingspace.controller;


import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.parkingspace.service.IPersonWalletService;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * <p>
 * 个人钱包表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/person-wallet")
public class PersonWalletController {

	@Resource
	private IPersonWalletService iPersonWalletService;

	@Resource
	private HttpServletResponse response;

	/**
	 * 查询钱包金额
	 * @param token 传入令牌
	 * @param role 传入当前用户身份数字 1.管理员,2.出租方,3.车主,4.物业
	 * @return 返回钱包剩余金额
	 */
	@GetMapping("/queryWalletAmount/{token}/{role}")
	public ResultVO queryWalletAmount (@PathVariable("token") String token, @PathVariable("role") Integer role) {
		try {
			Double aDouble = iPersonWalletService.queryWalletAmount(token, role);
			return new ResultVO(Constants.OPER_SUCCESS,"查询成功!",aDouble);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE,e.getMessage());
		}
	}

	/**
	 * 充值钱包金额
	 * @param token 传入令牌
	 * @param money 传入要充值的金额
	 * @return 返回Boolean
	 */
	@PutMapping("/walletRecharge/{token}/{money}")
	public ResultVO walletRecharge (@PathVariable("token") String token, @PathVariable("money") Double money) {
		try {
			Boolean aBoolean = iPersonWalletService.walletRecharge(token, money);
			return new ResultVO(Constants.OPER_SUCCESS,"操作成功!",aBoolean);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE,e.getMessage());
		}
	}


}

